home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / incr.test < prev    next >
Text File  |  1992-11-06  |  2KB  |  68 lines

  1. # Commands covered:  lreplace
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/incr.test,v 1.2 91/08/28 16:27:35 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. catch {unset x}
  21.  
  22. test incr-1.1 {basic incr operation} {
  23.     set x 23
  24.     list [incr x] $x
  25. } {24 24}
  26. test incr-1.2 {basic incr operation} {
  27.     set x 106
  28.     list [incr x -5] $x
  29. } {101 101}
  30.  
  31. test incr-2.1 {incr errors} {
  32.     list [catch incr msg] $msg
  33. } {1 {wrong # args: should be "incr varName ?increment?"}}
  34. test incr-2.2 {incr errors} {
  35.     list [catch {incr a b c} msg] $msg
  36. } {1 {wrong # args: should be "incr varName ?increment?"}}
  37. test incr-2.3 {incr errors} {
  38.     catch {unset x}
  39.     list [catch {incr x} msg] $msg $errorInfo
  40. } {1 {can't read "x": no such variable} {can't read "x": no such variable
  41.     while executing
  42. "incr x"}}
  43. test incr-2.4 {incr errors} {
  44.     set x abc
  45.     list [catch {incr x} msg] $msg $errorInfo
  46. } {1 {expected integer but got "abc"} {expected integer but got "abc"
  47.     (reading value of variable to increment)
  48.     invoked from within
  49. "incr x"}}
  50. test incr-2.5 {incr errors} {
  51.     set x 123
  52.     list [catch {incr x 1a} msg] $msg $errorInfo
  53. } {1 {expected integer but got "1a"} {expected integer but got "1a"
  54.     (reading increment)
  55.     invoked from within
  56. "incr x 1a"}}
  57. test incr-2.6 {incr errors} {
  58.     proc readonly args {error "variable is read-only"}
  59.     set x 123
  60.     trace var x w readonly
  61.     list [catch {incr x 1} msg] $msg $errorInfo
  62. } {1 {can't set "x": access disallowed by trace command} {can't set "x": access disallowed by trace command
  63.     while executing
  64. "incr x 1"}}
  65.  
  66. catch {unset x}
  67. concat {}
  68.